package config

import (
	"encoding/json"
	"io/ioutil"
)

// AppConfig holds the application configuration.
type AppConfig struct {
	DB             DBConfig `json:"db"` // Added nested DBConfig
	EdgeTTSPath    string   `json:"edge_tts_path"`
	AllowedOrigins []string `json:"allowed_origins"`
	// Add other configuration fields as needed
	ComfyUI ComfyUIConfig `json:"comfyui"`
}

// ComfyUIConfig holds ComfyUI configuration.
type ComfyUIConfig struct {
	ServerAddress string `json:"server_address"`
	ClientID      string `json:"client_id"`
}

// DBConfig holds database configuration.
type DBConfig struct {
	User     string `json:"user"`
	Password string `json:"password"`
	Host     string `json:"host"`
	Port     string `json:"port"`
	Database string `json:"database"`
}

var LoadedConfig *AppConfig

var ()

// LoadConfig loads the application configuration from a JSON file.
func LoadConfig(filePath string) (*AppConfig, error) {
	data, err := ioutil.ReadFile(filePath)
	if err != nil {
		return nil, err
	}

	var cfg AppConfig
	if err := json.Unmarshal(data, &cfg); err != nil {
		return nil, err
	}

	LoadedConfig = &cfg
	return LoadedConfig, nil
}
